package com.happyclub.paul.dao;

import com.happyclub.pojo.TbUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;


public interface UserRepostitory extends JpaRepository<TbUser,String> {

    TbUser findUserByTelephone(String telephone);

    /**
     * 查询该手机号是否注册
     * @param telephone
     * @return
     */
    @Query(value = "select u from TbUser u where u.telephone=:telephone")
    TbUser queryUserExists(@Param("telephone") String telephone);


    /**
     *@Description: 用户注册
     *@Author: 魏泉琦
     *@date: 2019/4/3
     */
    @Modifying
    @Query(value = "INSERT into TB_USER(USER_ID,NICK_NAME,SEX,TELEPHONE,CREATDTM,HEAD_PORTRAIT,AGE,PERSONALIZED_SIGNATURE,HOBBY,POST,HOMETOWN,CITY,EMAIL,USER_PASSWORD,SOLEMELBER) values(?1,?2,?3,?4,SYSDATE,?5,?6,?7,?8,?9,?10,?11,?12,?13,?14)",nativeQuery = true)
    Integer insertUserMsg(String userId, String nickName, String sex, String telephone, String headPortrait, long age, String personalizedSignature, String hobby, String post, String hometown, String city, String email, String userPassword, String soleMember);


    /**
     *@Description: 用户修改信息
     *@Author: 魏泉琦
     *@date: 2019/4/3
     */
    @Modifying
    @Query("update TbUser u set u.nickName=?1,u.sex=?2,u.headPortrait=?3,u.age=?4,u.personalizedSignature=?5,u.hobby=?6,u.post=?7,u.hometown=?8,u.city=?9,u.email=?10,u.userPassword=?11  where u.telephone=?12")
    Integer updateUserMsg(String nickName, String sex, String headPortrait, long age, String personalizedSignature, String hobby, String post, String hometown, String city, String email, String userPassword, String telephone);

    /**
     *@Description: 根据用户注册电话查询用户信息
     *@Author: 魏泉琦
     *@date: 2019/4/3
     */
    @Query("select u from TbUser u where u.telephone=:telephone")
    TbUser queryUserByTelephone(@Param("telephone") String telephone);


    /**
     *@Description: 根据用户编号查询用户信息
     *@Author: 魏泉琦
     *@date: 2019/4/3
     */
    @Query("select u from TbUser u where u.userId=:uid")
    TbUser queryUserById(@Param("uid") String uid);


    /**
     *@Description: 根据注册电话删除用户
     *@Author: 魏泉琦
     *@date: 2019/4/3
     */
    @Modifying
    @Query(value = "delete from TbUser u where u.telephone=:telephone")
    Integer deleteUserByTelephone(@Param("telephone") String telephone);


    /**
     *@Description: 根据用户编号删除用户
     *@Author: 魏泉琦
     *@date: 2019/4/3
     */
    @Modifying
    @Query(value = "delete from TbUser u where u.userId=:uid")
    Integer deleteUserById(@Param("uid")String uid);



}
